#pragma once

#include "Presentation/IPresentationRuntime.h"

class PresentationRuntime : public IPresentationRuntime
{
	typedef std::map<vclsid,vclsid> PresentationMap;
	typedef std::map<String,vclsid> PresentationWorkflowMap;
	typedef std::set<vclsid> DisabledPresentationTargetSet;
	typedef std::map<String,sys::ObjectPtr> PresentationWorkflowCache;

public:
	BEGIN_DEFINE_CLASS(CLSID_PresentationRuntime)
		DEFINE_INTERFACE_ENTRY(IPresentationRuntime)
	END_DEFINE_CLASS()

	PresentationRuntime();
	virtual ~PresentationRuntime();

	event_implement(PresentationWorkflowEventHandler,WorkflowRunning);
	event_implement(PresentationWorkflowEventHandler,WorkflowRunned);

public:
	virtual void RegisterPresentation(vclsid target,vclsid presentation);
	virtual void UnRegisterPresentation(vclsid target);
	virtual void DisablePresentation(vclsid target);

	virtual void RegisterWorkflow(const String& kind,vclsid presentationWorkflow);
	virtual void UnRegisterWorkflow(const String& kind);

	virtual void RunPresentation(Graphics* graphics,PresentationContext& context);
	virtual void RunWorkflow(IPresentationWorkflow* workflow,PresentationContext& context);

	virtual sys::ObjectPtr CreateWorkflow(const String& kind);

protected:
	bool IsPresentationEnabled(vclsid target) const;
	sys::ObjectPtr CreatePresentation(vclsid target);

private:
	PresentationMap m_presentationMap;
	DisabledPresentationTargetSet m_disabledpresentationTargetSet;
	PresentationWorkflowMap m_presetationWorkflowMap;

	PresentationWorkflowCache m_presentationWorkflows;
};

AUTO_REGISTER_CLASSMAP_ENTRY_singleton(PresentationRuntime)